From f62b2345f463695ef0f8f79830cd76b6e0332821 Mon Sep 17 00:00:00 2001
From: Rafi Zadanly <zadanlyr@gmail.com>
Date: Sat, 13 Jan 2024 10:35:22 +0700
Subject: Refactor src migrate folder

---
 src-migrate/pages/shop/product/[slug].tsx | 73 +++++++++++++++++++++++++++++++
 1 file changed, 73 insertions(+)
 create mode 100644 src-migrate/pages/shop/product/[slug].tsx

(limited to 'src-migrate/pages/shop/product/[slug].tsx')

diff --git a/src-migrate/pages/shop/product/[slug].tsx b/src-migrate/pages/shop/product/[slug].tsx
new file mode 100644
index 00000000..883532ed
--- /dev/null
+++ b/src-migrate/pages/shop/product/[slug].tsx
@@ -0,0 +1,73 @@
+import style from './product.module.css'
+
+import { GetServerSideProps, NextPage } from 'next'
+import React from 'react'
+import dynamic from 'next/dynamic'
+import cookie from 'cookie'
+
+import { getProductById } from '~/services/product'
+import { getIdFromSlug } from '~/libs/slug'
+import { IProductDetail } from '~/types/product'
+
+import { Seo } from '~/components/seo'
+
+const BasicLayout = dynamic(() => import('@/core/components/layouts/BasicLayout'), { ssr: false })
+const ProductDetail = dynamic(() => import('~/modules/product-detail'), { ssr: false })
+
+type PageProps = {
+  product: IProductDetail
+}
+
+export const getServerSideProps: GetServerSideProps<PageProps> = (async (context) => {
+  const { slug } = context.query
+  const cookieString = context.req.headers.cookie;
+  const cookies = cookieString ? cookie.parse(cookieString) : {};
+  const auth = cookies?.auth ? JSON.parse(cookies.auth) : {};
+  const tier = auth?.pricelist || ''
+
+  const productId = getIdFromSlug(slug as string)
+
+  const product = await getProductById(productId, tier)
+
+  if (!product) return { notFound: true }
+
+  return {
+    props: { product }
+  }
+})
+
+const ProductDetailPage: NextPage<PageProps> = ({ product }) => {
+  return (
+    <BasicLayout>
+      <Seo
+        title={`${product.name} - Indoteknik.com`}
+        description='Temukan pilihan produk B2B Industri &amp; Alat Teknik untuk Perusahaan, UMKM &amp; Pemerintah dengan lengkap, mudah dan transparan.'
+        openGraph={{
+          // url: process.env.NEXT_PUBLIC_SELF_HOST + router.asPath,
+          images: [
+            {
+              url: product?.image,
+              width: 800,
+              height: 800,
+              alt: product?.name,
+            },
+          ],
+          type: 'product',
+        }}
+        additionalMetaTags={[
+          {
+            name: 'keywords',
+            content: `${product?.name}, Harga ${product?.name}, Beli ${product?.name}, Spesifikasi ${product?.name}`,
+          }
+        ]}
+        // canonical=''
+      />
+
+      <div className='md:container pt-10'>
+        <ProductDetail product={product} />
+      </div>
+    </BasicLayout>
+  )
+}
+
+export default ProductDetailPage
\ No newline at end of file
-- 
cgit v1.2.3


From a70fd5b6d9c7a769ac1aaa22a7d037ba3be27a05 Mon Sep 17 00:00:00 2001
From: Rafi Zadanly <zadanlyr@gmail.com>
Date: Tue, 16 Jan 2024 16:08:43 +0700
Subject: Update improve product detail performance

---
 src-migrate/pages/shop/product/[slug].tsx | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

(limited to 'src-migrate/pages/shop/product/[slug].tsx')

diff --git a/src-migrate/pages/shop/product/[slug].tsx b/src-migrate/pages/shop/product/[slug].tsx
index 883532ed..733e10d9 100644
--- a/src-migrate/pages/shop/product/[slug].tsx
+++ b/src-migrate/pages/shop/product/[slug].tsx
@@ -1,5 +1,3 @@
-import style from './product.module.css'
-
 import { GetServerSideProps, NextPage } from 'next'
 import React from 'react'
 import dynamic from 'next/dynamic'
@@ -10,6 +8,7 @@ import { getIdFromSlug } from '~/libs/slug'
 import { IProductDetail } from '~/types/product'
 
 import { Seo } from '~/components/seo'
+import { useRouter } from 'next/router'
 
 const BasicLayout = dynamic(() => import('@/core/components/layouts/BasicLayout'), { ssr: false })
 const ProductDetail = dynamic(() => import('~/modules/product-detail'), { ssr: false })
@@ -36,14 +35,18 @@ export const getServerSideProps: GetServerSideProps<PageProps> = (async (context
   }
 })
 
+const SELF_HOST = process.env.NEXT_PUBLIC_SELF_HOST
+
 const ProductDetailPage: NextPage<PageProps> = ({ product }) => {
+  const router = useRouter();
+
   return (
     <BasicLayout>
       <Seo
         title={`${product.name} - Indoteknik.com`}
         description='Temukan pilihan produk B2B Industri &amp; Alat Teknik untuk Perusahaan, UMKM &amp; Pemerintah dengan lengkap, mudah dan transparan.'
         openGraph={{
-          // url: process.env.NEXT_PUBLIC_SELF_HOST + router.asPath,
+          url: SELF_HOST + router.asPath,
           images: [
             {
               url: product?.image,
@@ -60,10 +63,10 @@ const ProductDetailPage: NextPage<PageProps> = ({ product }) => {
             content: `${product?.name}, Harga ${product?.name}, Beli ${product?.name}, Spesifikasi ${product?.name}`,
           }
         ]}
-        // canonical=''
+        canonical={SELF_HOST + router.asPath}
       />
 
-      <div className='md:container pt-10'>
+      <div className='md:container pt-4 md:pt-6'>
         <ProductDetail product={product} />
       </div>
     </BasicLayout>
-- 
cgit v1.2.3


From 8a671dd0ecf1f91f06d6913538742085fefe9990 Mon Sep 17 00:00:00 2001
From: Rafi Zadanly <zadanlyr@gmail.com>
Date: Tue, 23 Apr 2024 16:13:43 +0700
Subject: Fix whatsapp url on basic layout

---
 src-migrate/pages/shop/product/[slug].tsx | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

(limited to 'src-migrate/pages/shop/product/[slug].tsx')

diff --git a/src-migrate/pages/shop/product/[slug].tsx b/src-migrate/pages/shop/product/[slug].tsx
index 733e10d9..fc72a6b0 100644
--- a/src-migrate/pages/shop/product/[slug].tsx
+++ b/src-migrate/pages/shop/product/[slug].tsx
@@ -1,5 +1,5 @@
 import { GetServerSideProps, NextPage } from 'next'
-import React from 'react'
+import React, { useEffect } from 'react'
 import dynamic from 'next/dynamic'
 import cookie from 'cookie'
 
@@ -9,6 +9,7 @@ import { IProductDetail } from '~/types/product'
 
 import { Seo } from '~/components/seo'
 import { useRouter } from 'next/router'
+import { useProductContext } from '@/contexts/ProductContext'
 
 const BasicLayout = dynamic(() => import('@/core/components/layouts/BasicLayout'), { ssr: false })
 const ProductDetail = dynamic(() => import('~/modules/product-detail'), { ssr: false })
@@ -40,6 +41,12 @@ const SELF_HOST = process.env.NEXT_PUBLIC_SELF_HOST
 const ProductDetailPage: NextPage<PageProps> = ({ product }) => {
   const router = useRouter();
 
+  const { setProduct } = useProductContext();
+
+  useEffect(() => {
+    if (product) setProduct(product);
+  }, [product, setProduct]);
+
   return (
     <BasicLayout>
       <Seo
-- 
cgit v1.2.3

